package com.ambow.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigInteger;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.ambow.dao.Operat;



/**
 * Servlet implementation class Person_psw_modifyServlet
 */
@WebServlet("/Person_psw_modifyServlet")
public class Person_psw_modifyServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Person_psw_modifyServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		String status=request.getParameter("status");  //接收从jsp页面传来的status
		PrintWriter out = response.getWriter();
		HttpSession  hs = request.getSession(); 
		String psw=(String)hs.getAttribute("operator_password").toString();
		if(status.equals("psw_modify")){                       //密码修改判断
			//接收传来的密码信息
			String old_psw = request.getParameter("old_psw");
			String new_psw = request.getParameter("psw");
			String confirmPsw_psw = request.getParameter("confirmPsw_psw");
			
			if(new_psw.equals(confirmPsw_psw)&&old_psw.equals(psw)){//新密码和确认密码比较，旧密码和登录时存入session的密码相比较
				System.out.println(old_psw);
				System.out.println(new_psw);
				System.out.println(confirmPsw_psw);
				
				int id= (Integer) hs.getAttribute("operator_id");//获取存入session中的操作者的id
				Operat person_info = new Operat();
				person_info.updatePerson(new_psw,id);//密码修改操作
//				response.sendRedirect("static/module/person/person001/user_detail.jsp");
				out.print("修改成功！！！");;
			}
			else{
				out.print("修改失败！");
//				request.getRequestDispatcher("../pages/admin/index.jsp").forward(request, response);
			}
			


		}
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doGet(request, response);
	}

}
